package com.mtw.bbs.bbsUser.config;

import com.github.wujun234.uid.impl.CachedUidGenerator;
import com.github.wujun234.uid.impl.UidProperties;
import com.mtw.bbs.bbsUser.utils.DisposableWorkerIdAssignerImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * uid生成配置
 */
@Configuration
public class UIDConfig {

    @Bean
    public CachedUidGenerator defaultUidGenerator(DisposableWorkerIdAssignerImpl disposableWorkerIdAssigner) {

        UidProperties uidProperties = new UidProperties();
        // 时间位, 默认:30
        uidProperties.setTimeBits(28) ;
        // 机器位, 默认:16
        uidProperties.setWorkerBits(6);
        // 序列号, 默认:7
        uidProperties.setSeqBits(1) ;
        // 初始时间, 默认:"2019-02-20"
        uidProperties.setEpochStr("2023-01-01") ;
        CachedUidGenerator cachedUidGenerator = new CachedUidGenerator(uidProperties) ;
        cachedUidGenerator.setWorkerIdAssigner(disposableWorkerIdAssigner) ;
        return cachedUidGenerator ;
    }





}
